#include "elk_common_dlg.h"
#include <QDialog>
#include <QListView>
#include <QTextBrowser>
#include <QVBoxLayout>
#include <QStandardItemModel>

void ElkCommonDlg::showDlg(QWidget *parent,
                           QWidget *content,
                           const QString &title)
{
    QDialog dlg(parent);
    dlg.resize(680, 320);
    dlg.setWindowTitle(title);

    content->setParent(&dlg);

    QVBoxLayout *verticalLayout = new QVBoxLayout(&dlg);
    verticalLayout->addWidget(content);

    dlg.exec();
}

void ElkCommonDlg::showListViewDlg(QWidget *parent,
                                   const QString &title,
                                   const QStringList &list)
{
    QListView *listView = new QListView();
    listView->setEditTriggers(QAbstractItemView::NoEditTriggers);

    QStandardItemModel *model_ = new QStandardItemModel(listView);
    listView->setModel(model_);

    QList<QStandardItem*> items;
    for (auto text : list) {
        auto item = new QStandardItem(text);
        items.append(item);
        model_->appendRow(item);
    }

    showDlg(parent, listView, title);
}

void ElkCommonDlg::showTextBrowserDlg(QWidget *parent,
                                      const QString &title,
                                      const QStringList &list)
{
    QTextBrowser *textBrowser = new QTextBrowser();
    textBrowser->setWordWrapMode(QTextOption::WrapAnywhere);
    textBrowser->setLineWrapMode(QTextBrowser::WidgetWidth);

    for (auto text : list) {
        textBrowser->append(text);
    }
    showDlg(parent, textBrowser, title);
}
